package com.review.Test;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class User implements Delayed{
	
	private TimeUnit tu = TimeUnit.MINUTES;
	
	private long endTime;
	private String name;

	public long getEndTime() {
		return endTime;
	}

	public void setEndTime(long endTime) {
		this.endTime = endTime;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public User(long endTime, String name) {
		super();
		this.endTime = endTime;
		this.name = name;
	}
	
	@Override
	public String toString() {
		return "User [endTime=" + endTime + ", name=" + name + "]";
	}

	@Override
	public int compareTo(Delayed o) {//采用二叉树算法对元素进行排序
		User user = (User)o;
		return this.getDelay(this.tu) - user.getDelay(this.tu) >0 ? 1:-1;
	}

	@Override
	public long getDelay(TimeUnit unit) {//获取元素在队列中剩余的时间----默认为毫秒
		return this.endTime - System.currentTimeMillis();
	}

}
